package tum0r.cryptology.decryption;

import tum0r.misc.StringUtils;

/**
 * 工程: JavaTools<br>
 * 包: tum0r.cryptology.decryption<br>
 * 创建者: tum0r<br>
 * 创建时间: 2020/8/22 20:20<br>
 * <br>
 */
public class RailFenceDecryption {
    public String decryption(String cipherText, int num) {
        StringBuilder stringBuilder = new StringBuilder();
        if (StringUtils.isNullOrEmptyOrSpace(cipherText) && num > 1) {
            char[] temp = cipherText.toCharArray();
            int length = temp.length;
            int maxCount = (int) (length / (double) num + 0.5);
            for (int count = 0; count < maxCount; count++) {
                for (int now = count; now < length; now += maxCount) {
                    stringBuilder.append(temp[now]);
                }
            }
        }
        return stringBuilder.toString();
    }
}
